import 'dart:convert';

import 'ni_base_model.dart';

///位置数据信息
class NILocation implements NIModel {
  double? longitude;
  double? latitude;
  double? direction;
  double? altitude;
  double? radius;

  NILocation(
      {this.longitude = 0.0,
      this.latitude = 0.0,
      this.direction = 0.0,
      this.altitude = 0.0,
      this.radius = 500});

  factory NILocation.fromJson(String json) {
    Map<String, dynamic> map = jsonDecode(json);
    return NILocation.fromMap(map);
  }

  factory NILocation.fromMap(Map<String, dynamic> map) {
    return NILocation(
      longitude: map['longitude'],
      latitude: map['latitude'],
      direction: map['direction'],
      altitude: map['altitude'],
      radius: map['radius'],
    );
  }

  @override
  String toJson() {
    return '{"longitude":$longitude,"latitude":$latitude,"direction":$direction,"altitude":$altitude,"radius":$radius}';
  }

  @override
  Map<String, dynamic> toMap() {
    return {
      "longitude": longitude,
      "latitude": latitude,
      "direction": direction ?? 0.0,
      "altitude": altitude ?? 0.0,
      "radius": radius ?? 0.0
    };
  }
}
